package com.itheima.TCP.TCP接收协议;


import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo3 {
    public static void main(String[] args) throws IOException {
        //创建服务器端ServerSocket
        ServerSocket ss = new ServerSocket(2);
        //监听客户端连接
        Socket accept = ss.accept();
        //从客户端读取网络中的流
        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        //本地IO流，把数据写到本地中，实现永久话存储
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day629_网络编程入门\\images\\969.jpg"));

        byte[] bys = new byte[1024];
        int len;
        while ((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);
            bos.flush();
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();
        bos.close();
        accept.close();
    }
}
